#include "kernel/cell.hpp"


NaK:: ~NaK() throw()
{
}

NaK:: NaK( lua_State *L ) :
Enzyme( L, "NaK", "efficiencyNaK" ),
J( L, "JNaK" ),
sNa("Na+"),
sK("K+"),
C50( 1e-5 ),
K50( C50*C50*C50 )
{
	
}


Real NaK:: saturation( const Solution &S_in )
{
	const Real Na = S_in[ sNa ];
	const Real Na3 = Na*Na*Na;
	const Real fac = Na3/(Na3+K50);
	return fac;
}

BIO_PH_ENZYME_CALL( NaK:: )
{
	Real rho = V * (cell.Surface * J( zeta_m ) / cell.Volume);
	rho *= saturation(S_in);
	rho *= efficiency(t);
	dS[ sK  ] += 2 * rho;
	dS[ sNa ] -= 3 * rho;
	return rho;
	
}

Real NaK:: getJ( Real zeta ) 
{
	return J(zeta);
}


Real NaK:: drho_dzeta(Real zeta_m, const Cell &cell )
{
	derivative<Real>        drvs;
	numeric<Real>::function func(this,& NaK::getJ );
	const Real dJ = drvs(func,zeta_m,1e-2);
	
	return V * (cell.Surface * dJ / cell.Volume) * saturation(cell.solutions[ Cell::iS_in] );
}